package com.ywjt.platformbusiness.my.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.ywjt.platformbusiness.R;
import com.ywjt.platformbusiness.base.BaseActivity;
import com.ywjt.platformbusiness.my.adapter.InvestAdapter;
import com.ywjt.platformbusiness.util.ToastUtil;

import java.util.ArrayList;
import java.util.List;

public class ActivityInvest extends BaseActivity implements View.OnClickListener {
    private LinearLayout llWxPay,llAliPay;
    private ImageView ivSelect1,ivSelect2,ivAgree;
    private TextView tvSureInvest;
    private ImageView ivBack;

    private RecyclerView rcCommon;
    private List<String> data;
    private InvestAdapter adapter;

    private Boolean isAgree=false;
    public static void actionStart(Context context) {
        Intent intent = new Intent(context, ActivityInvest.class);
        context.startActivity(intent);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.llWxPay:
                ivSelect1.setVisibility(View.VISIBLE);
                ivSelect2.setVisibility(View.GONE);
                break;
            case R.id.llAliPay:
                ivSelect1.setVisibility(View.GONE);
                ivSelect2.setVisibility(View.VISIBLE);
                break;
            case R.id.ivAgree:
                if (!isAgree){
                    ivAgree.setImageResource(R.mipmap.icon_address_selected);
                }else {
                    ivAgree.setImageResource(R.mipmap.icon_address_unselected);
                }
                isAgree=!isAgree;
                break;
            case R.id.tvSureInvest:
                //确认充值
                if (!isAgree){
                    //没有统一服务协议
                    ToastUtil toastUtil=new ToastUtil(ActivityInvest.this,R.layout.popu_success1,"请先同意用户充值协议",1);
                    toastUtil.show();
                }
                //调用接口充值
                break;
            case R.id.ivBack:
                finish();
                break;
        }
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        setAndroidNativeLightStatusBar(true);
    }

    @Override
    protected int setLayoutResourceID() {
        return R.layout.activity_invest;
    }

    @Override
    protected void initView(){
        rcCommon=findViewById(R.id.rcCommon);
        llWxPay=findViewById(R.id.llWxPay);
        ivBack=findViewById(R.id.ivBack);
        ivAgree=findViewById(R.id.ivAgree);
        ivSelect1=findViewById(R.id.ivSelect1);
        ivSelect2=findViewById(R.id.ivSelect2);
        llAliPay=findViewById(R.id.llAliPay);
        tvSureInvest=findViewById(R.id.tvSureInvest);
        data=new ArrayList<>();
        data.add("");
        data.add("");
        data.add("");
        data.add("");
        data.add("");
        data.add("");
        data.add("");
        data.add("");
        data.add("");
        adapter=new InvestAdapter(data);
        rcCommon.setLayoutManager(new GridLayoutManager(this,3,RecyclerView.VERTICAL,false));
        rcCommon.setAdapter(adapter);

        llWxPay.setOnClickListener(this::onClick);
        llAliPay.setOnClickListener(this::onClick);
        ivAgree.setOnClickListener(this::onClick);
        tvSureInvest.setOnClickListener(this::onClick);
        ivBack.setOnClickListener(this::onClick);

    }

    @Override
    protected void initData() {

    }

    /**
     * 获取要使用的标题栏样式(此函数由子类重写)
     *
     * @return
     */
    @Override
    protected int getTitleBarType() {
        return TITLEBAR_NULL;
    }
}
